<script setup>
import { ref, nextTick, computed } from "vue";
import ShopSku from "./ShopSku.vue";
import ModalTable from "./ModalTable.vue";
const props = defineProps({
  formInline: {
    type: Array,
    default: () => [],
  },
  tableConfig: {
    type: Array,
    default: () => [],
  },
});
const tabName = ref("");
const tableLoading = ref(false);
const modalTableRef = ref();
const seachTableRef = ref();
const modalRef = ref();
const modalTitle = ref("设置价格");
const formInlines = ref([
  {
    type: "select",
    width: "180",
    placeholder: "经营品牌",
    label: "",
    prop: "type",
    data: [
      {
        label: "审方",
        value: 2,
      },
      {
        label: "咨询",
        value: 1,
      },
    ],
    model: [],
  },
  {
    type: "select",
    width: "180",
    placeholder: "批发规则",
    label: "",
    prop: "type",
    data: [
      {
        label: "审方",
        value: 2,
      },
      {
        label: "咨询",
        value: 1,
      },
    ],
    model: [],
  },
]);
const btnLefts = ref([
  {
    label: "导出",
    plain: false,
    show: true,
    img: new URL("@/assets/icon/btn-export.png", import.meta.url),
    style: "border-color:#0C268C;color:#0C268C",
    click: async () => {
      //
    },
  },
]);
const tableConfigs = ref([
  {
    prop: "fzr",
    label: "经营品牌",
  },
  {
    prop: "lsjg",
    needHeader: true,
    headerContent:
      '<div style="width:256px;">统一价格：对各个门店批发商品时，默认取「商品库-基础信息」中的批发价<br/>分组定价：设置分组价格后，将按照各组的批发价格对门店进行批发</div>',
    label: "分组定价",
    width: "110",
  },
  {
    type: "action",
    label: "操作",
    width: 220,
    btns: [
      {
        label: () => "设置分组价格",
        type: "success",
        show: (row) => {
          return false;
        },
        click: async (row) => {
          modalTitle.value = "设置价格";
          modalItem.value = row;
          modalItemState.value = 1;
          modalRef.value.open();
          nextTick(() => {
            modalTableRef.value.setTable([
              {
                mdfz: "",
                pfjgz: "按百分比加价",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: true,
              },
              {
                mdfz: "华东地区",
                pfjgz: "",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: false,
              },
            ]);
          });
        },
      },
      {
        label: () => "修改分组价格",
        type: "warning",
        show: (row) => {
          return true;
        },
        click: async (row) => {
          modalTitle.value = "设置价格";
          modalItem.value = row;
          modalItemState.value = 1;
          modalRef.value.open();
          nextTick(() => {
            modalTableRef.value.setTable([
              {
                mdfz: "",
                pfjgz: "按百分比加价",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: true,
              },
              {
                mdfz: "华东地区",
                pfjgz: "",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: false,
              },
            ]);
          });
        },
      },
      {
        label: () => "查看",
        type: "primary",
        show: (row) => {
          return true;
        },
        click: async (row) => {
          modalItem.value = row;
          modalTitle.value = "批发价详情";
          modalItemState.value = 0;
          modalRef.value.open();
          nextTick(() => {
            modalTableRef.value.setTable([
              {
                mdfz: "",
                pfjgz: "按百分比加价",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: true,
              },
              {
                mdfz: "华东地区",
                pfjgz: "",
                pfjgzjj: "+",
                pfjgzbfb: "",
                pfjgzgd: "",
                state: false,
              },
            ]);
          });
        },
      },
    ],
  },
]);

const totalPage = ref(0);
const tableData = ref([]);

const handlerSearch = async (formInline) => {
  tableLoading.value = true;
  try {
    totalPage.value = 100;
    tableData.value = [
      {
        ygxm: "1",
        dlzh: "2",
        js: "3",
        state: true,
        bm: "5",
        zjgx: "6",
        imgSrc:
          "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg",
        name: "产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称产品名称",
      },
    ];
    tableLoading.value = false;
  } catch (e) {
    tableLoading.value = false;
  }
};
const closeModal = () => {
  modalRef.value.close();
};

const submitModal = () => {};
const modalItem = ref({});
const modalItemState = ref(0);
const modalTableLoading = ref(false);

const initSearch = (e) => {
  tabName.value = e;
};
defineExpose({ handlerSearch, initSearch });
</script>

<template>
  <div class="page-content mt4">
    <SeachTable
      :tableType="1"
      ref="seachTableRef"
      :forms="formInline.concat(formInlines)"
      :btnLefts="btnLefts"
      :tableLoading="tableLoading"
      :tableConfig="tableConfig.concat(tableConfigs)"
      :tableData="tableData"
      :totalPage="totalPage"
      @handlerSearch="handlerSearch"
    >
      <template #phone="{ row }">
        <div class="project_info">
          <div class="img">
            <el-image
              :src="row.imgSrc"
              lazy
              :preview-src-list="[row.imgSrc]"
              :initial-index="0"
              style="width: 100%; height: 100%"
              preview-teleported
              hide-on-click-modal
            />
          </div>
          <el-tooltip placement="top" v-if="row.name?.length > 26">
            <template #content
              ><div class="name_info">
                {{ row.name }}
              </div>
            </template>
            <div class="name_info uni-ellipsis">
              {{ row.name }}
            </div>
          </el-tooltip>
          <div v-else class="name_info uni-ellipsis">
            {{ row.name }}
          </div>
        </div>
      </template>
    </SeachTable>
  </div>
  <Modal ref="modalRef" :title="modalTitle" :top="'15vh'" :width="'720px'">
    <template #content>
      <div class="shopBox">
        <div class="shop_name">
          <div class="head">
            <ShopSku></ShopSku>
            <div class="head_txt">颈椎病/肩周炎/网球肘单次体验套餐</div>
          </div>
          <div class="footer">2048103958024</div>
        </div>
        <div class="shop_price">
          <div class="lines"></div>
          <div class="">
            <div class="price">25.01</div>
            <div class="price_txt">批发价</div>
          </div>
          <div class="lines"></div>
          <div class="">
            <div class="price">20</div>
            <div class="price_txt">会员价</div>
          </div>
        </div>
      </div>
      <ModalTable
        ref="modalTableRef"
        :item="modalItem"
        :state="modalItemState"
        :title="'批发'"
      ></ModalTable>
    </template>
    <template #footer>
      <div>
        <el-button @click="closeModal">取消</el-button>
        <el-button type="primary" @click="submitModal">确定</el-button>
      </div>
    </template>
  </Modal>
</template>

<style lang="less" scoped>
.shopBox {
  margin-top: 14px;
  padding: 12px;
  background: #f6f6f6;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .shop_name {
    // flex: 1;
    .head {
      display: flex;
      align-items: center;

      .head_txt {
        margin-left: 8px;
        color: #000000;
        font-size: 16px;
        font-style: normal;
        font-weight: 600;
        line-height: 16px;
      }
    }
    .footer {
      margin-top: 14px;
      color: #222222;
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
      line-height: 14px;
    }
  }
  .lines {
    height: 46px;
    width: 1px;
    background: #d9d9d9;
  }
  .shop_price {
    flex: 1;
    margin-left: 24px;
    display: flex;
    align-items: center;
  }
  .price {
    padding-left: 24px;
    padding-right: 24px;
    color: #ff2440;
    font-size: 20px;
    font-weight: 600;
  }
  .price_txt {
    padding-left: 24px;
    padding-right: 24px;
    margin-top: 12px;
    color: #222222;
    font-size: 14px;
    font-weight: 400;
  }
}

.project_info {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .img {
    width: 48px;
    height: 48px;
  }
  .name_info {
    flex: 1;
    box-sizing: border-box;
    padding-left: 8px;
    color: #222222;
    font-weight: bold;
    font-size: 14px;
  }
}
</style>
